package com.blate.dogxiao.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * @author Blate
 * Created in 2021/4/21
 */
public class ConversationBean
        implements Parcelable {

    public String avatar;
    public String nickname;
    public String phoneNumber;
    public int gender;
    public String lastMsg;
    public String lastMsgTime;
    public List<Msg> msgs;

    public ConversationBean() {
    }

    protected ConversationBean(Parcel in) {
        avatar = in.readString();
        nickname = in.readString();
        phoneNumber = in.readString();
        gender = in.readInt();
        lastMsg = in.readString();
        lastMsgTime = in.readString();
        msgs = in.createTypedArrayList(Msg.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(avatar);
        dest.writeString(nickname);
        dest.writeString(phoneNumber);
        dest.writeInt(gender);
        dest.writeString(lastMsg);
        dest.writeString(lastMsgTime);
        dest.writeTypedList(msgs);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<ConversationBean> CREATOR = new Creator<ConversationBean>() {
        @Override
        public ConversationBean createFromParcel(Parcel in) {
            return new ConversationBean(in);
        }

        @Override
        public ConversationBean[] newArray(int size) {
            return new ConversationBean[size];
        }
    };

    public static class Msg
            implements Parcelable {

        public static final int OTHER = 0;
        public static final int SELF = 1;

        public String msg;
        public int owner;

        public Msg() {
        }

        protected Msg(Parcel in) {
            msg = in.readString();
            owner = in.readInt();
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(msg);
            dest.writeInt(owner);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<Msg> CREATOR = new Creator<Msg>() {
            @Override
            public Msg createFromParcel(Parcel in) {
                return new Msg(in);
            }

            @Override
            public Msg[] newArray(int size) {
                return new Msg[size];
            }
        };
    }

}
